import React, { useState } from 'react'
import { ArrowLeft } from '@nutui/icons-react'
import { useNavigate } from 'react-router-dom'
import { Uploader, Cell } from '@nutui/nutui-react'
import instance from '../http/instance'
import Shang from './upload'
export default function Adddongtai() {
  const navigate = useNavigate()
  const [content, setContent] = useState('')
  // const [files,setFiles]=useState()
  // const handleFileChange=(e)=>{
  //     const [file]=e.target.files
  //     setFiles(file)
  //  }
  //  const createFileChunk=(file,chunkSize=1024*1024)=>{
  //   const fileChunklist=[]
  //   let cur=0
  //   while(cur<file.size){
  //     const chunk=file.slice(cur,cur+chunkSize)
  //     fileChunklist.push(chunk)
  //     cur+=chunkSize}
  //     return fileChunklist
  //  }
  //  const uploadChunks=async (newFile)=>{
  //   const requestList=newFile.map(({chunk,hash})=>{
  //     const formData=new FormData()
  //     formData.append('file',chunk)
  //     formData.append('hash',hash)
  //     formData.append('filename',newFile[0].name)
  //     return {formData}
  //   })
  //   .map(({formData})=>{
  //     return fetch('http://127.0.0.1:8000/upload',formData)
  //   })
  //   await Promise.all(requestList)
  //   await mergeRequest()
  //  }
  //  const mergeRequest=async ()=>{
  //   const data={size:SIZE,filename:files.name}
  //   await request.post('http://127.0.0.1:8000/load',data)
  //  }
  const fal = instance
  const uploadUrl = 'http://127.0.0.1:8000/uploadimg'
  const onStart = () => {
    console.log('start触发')
  }
  const beforeUpload = async (files) => {
    const allowedTypes = ['image/png']
    const filteredFiles = Array.from(files).filter((file) =>
      allowedTypes.includes(file.type)
    )
    return filteredFiles
  }
  return (
    <div>
      <p style={{ marginLeft: '10px', marginTop: '10px' }}><ArrowLeft onClick={() => {
        navigate('/cate')
      }} width={20} height={20} />
        <span style={{ display: 'inline-block', marginLeft: '2.6rem', fontSize: '20px', fontWeight: 'bolder' }}>发布动态</span>
        <span style={{ display: 'inline-block', marginLeft: '2rem', fontSize: '12px', paddingBottom: '5px', color: 'pink' }}> 发布</span>
      </p>
      <textarea value={content} placeholder='输入内容' onChange={(e) => {
        setContent(e.target.value)
      }} style={{
        width: '80%',
        marginLeft: '0.6rem',
        marginTop: '0.2rem',
        height: '300px',
        borderRadius: '5px',
        padding: '0.1rem',
        border: '1px solid #ccc'
      }} />
      <Uploader
        url={uploadUrl}
        uploadLabel="上传图片"
        deletable={fal}
        onStart={onStart}
        style={{ marginLeft: "0.6rem", marginTop: '0.2rem', '--nutui-uploader-image-width': "150px", "--nutui-uploader-image-height": '150px' }}
      />
      <Shang></Shang>
    </div>
  )
}
